package com.eastmoney.emis.edda.controller;

import com.eastmoney.emis.edda.domain.service.EddaServeTimeService;
import com.eastmoney.emis.edda.domain.service.eddi.EddiInstructionCommand;
import com.eastmoney.emis.edda.domain.service.eddi.EddiService;
import com.eastmoney.emis.edda.domain.valueobject.ServiceType;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @description: Description
 * @projectName: EDDA-HSBC
 * @package: com.eastmoney.emis.edda.controller
 * @author: 汪程程
 * @date: 2022/9/29 6:06 PM
 * @version: 1.0
 */
@RestController
@RequestMapping("/api/eddi/hsbc")
@ApiOperation("HSBC EDDI发起")
public class HsbcEddiController {

    @Autowired
    private EddiService eddiService;
    @Autowired
    private EddaServeTimeService eddaServeTimeService;

    @PostMapping
    public void debitInstruction(@Validated @RequestBody EddiInstructionCommand command) {
        if (eddaServeTimeService.serving(ServiceType.EDDI)) {
            eddiService.debitInstructionAsync(command);
            return;
        }
        eddiService.debitInstructionOffline(command);
    }

}
